package br.com.news.business.utils;

import javax.inject.Named;

import org.apache.velocity.Template;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

@Named
public class VelocityTemplateFactory {

	private final String VELOCITY_FOLDER = "VELOCITY_TEMPLATES/";
	
	public Template getTemplate(final String templateName) throws Exception {
        VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "class");
        ve.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
        ve.init();  
		return ve.getTemplate(VELOCITY_FOLDER + templateName);
	}
	
}
